home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.unix.programmer
- Path: news.uunet.ca!wildcan!sq!msb
- From: msb@sq.com (Mark Brader)
- Subject: Re: Q: '\n' character
- Message-ID: <1996Apr15.185025.564@sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <4kj66f$k0o@ren.cei.net> <4kmhpsINN7ak@keats.ugrad.cs.ubc.ca> <AD97189A966891F2@mcdiala02.it.luc.edu> <4ktn04INNoev@keats.ugrad.cs.ubc.ca>
- Date: Mon, 15 Apr 1996 18:50:25 GMT
-
- Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) writes:
- > A lot of the standard I/O library ... had to be standardized
- > a certain way to reflect existing practice and preserve the
- > correctness of existing programs.
- >
- > Having a return value that is the same as one of the arguments is
- > a complete waste of a ``data path'' that could be used to return
- > pertinent information.
-
- Quite right.
-
- > Or better still: how about returning a pointer to the last character
- > read! This would point to a null character if _no_ characters
- > were read (thus indicating EOF on the attempt to read the first
- > character), or to either a newline or a non-newline if at least one
- > character was read.
-
- This would certainly have been an improvement. It would also had made
- it rather more convenient to recover semi-gracefully in the case where
- there are nulls (meaning null characters, of course) in the input. With
- the actual fgets(), to find all the nulls in the input line, you have to
- scan for each instance in the buffer of a null *not* preceded by a newline,
- up to and excluding a null that *is* preceded by a newline *or* a null in
- the last character of the buffer. With a pointer to the end of what was
- read, you wouldn't have to look at the context of each null.
-
- Similarly, it would be more convenient if sprintf() returned a pointer
- to the null at the end of what it just wrote, so that the next sprintf()
- call could start from there. In pre-ANSI implementations it sometimes
- returned a redundant pointer to the start of its buffer; at least ANSI
- standardized on the other behavior that existed, returning the number
- of characters written, so the pointer to the null can be computed.
-
- Things that might have been.
- --
- Mark Brader | "A standard is established on sure bases, not capriciously
- msb@sq.com | but with the surety of something intentional and of a logic
- SoftQuad Inc. | controlled by analysis and experiment. ... A standard is
- Toronto | necessary for order in human effort." -- Le Corbusier
-
- My text in this article is in the public domain.
-